package com.ss.android.article.base.feature.video;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.a;
import android.util.Base64;

public class MediaHelper {
    public static final String INTENT_PLAY_JSON = "play_json";
    public static final String INTENT_PLAY_URL = "play_url";
    public static final String INTENT_REFERER_URL = "referer_url";
    public static final String INTENT_USER_AGENT = "user_agent";

    public MediaHelper() {

    }

    public static String getVideoSource(String arg4) {
        String v1 = "";
        if (!a.isTextEmpty(arg4)) {
            try {
                String v0_1 = new String(Base64.decode(arg4, 0), "utf-8");
                return v0_1;
            } catch (Throwable v0) {
            }
        }

        return v1;
    }

    public static void startMediaPlayerActivity(Context context, String playUrl, String playJson, String refererUrl, String userAgent, Bundle bundle) {
        Intent intent = new Intent();
        intent.setClassName(context, "com.ss.android.video.MediaPlayerActivity");
        if (bundle != null) {
            intent.putExtras(bundle);
        }

        intent.putExtra("play_url", playUrl);
        intent.putExtra("play_json", playJson);
        intent.putExtra("referer_url", refererUrl);
        intent.putExtra("user_agent", userAgent);
        context.startActivity(intent);
    }

    public static int timeToPercent(long totalPlayTime, long duration) {
        if (duration > 0) {
            return (int) ((double) totalPlayTime / (double) duration * 100);
        } else {
            return 0;
        }
    }
}

